package com.minisoft.pms;

import cn.hutool.core.util.XmlUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

public class WorkflowClient {

    private static final String SERVICE_URL = "http://172.16.51.245:88/services/InitProcessInterface";

    public static void main(String[] args) {
        String requestXml = "<workflowRequestInfo>" +
                "    <saplcbh>f519215dc52a434dbd7899f62dcbcb90</saplcbh>\n" +
                "    <saplclx>PMS</saplclx>\n" +
                "    <creatorId>linshuying</creatorId>\n" +
                "    <isNext>0</isNext>\n" +
                "    <requestName>华发数智项目变更审批表</requestName>\n" +
                "    <workflowId>22442</workflowId>\n" +
                " </workflowRequestInfo>";
        requestXml = XmlUtil.escape(requestXml);
        // 创建HttpRequest对象
        HttpRequest request = HttpUtil.createPost(SERVICE_URL);

        // 设置请求头
        request.header("Content-Type", "text/xml; charset=utf-8");
        request.header("SOAPAction", "");

        // 设置请求体
        String soapRequest = buildSoapRequest(requestXml);
        request.body(soapRequest);

        // 发送请求并接收响应
        HttpResponse response = request.execute();
        String responseBody = response.body();

        // 处理响应
        System.out.println("Response: " + responseBody);
    }

    private static String buildSoapRequest(String xmlData) {
        return "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"webservice.InitProcess.westvalley.com\">" +
               "<soapenv:Header/>" +
               "<soapenv:Body>" +
               "<web:createOrUpdateWorkflow>" +
               "<xml>" + xmlData + "</xml>" +
               "</web:createOrUpdateWorkflow>" +
               "</soapenv:Body>" +
               "</soapenv:Envelope>";
    }
}
